package com.mshop.m;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.mshop.fw.modules.SM;
import com.mshop.fw.util.DESUtil;
import com.mshop.po.Drivers;
import com.mshop.po.Users;
import com.mshop.util.WebContext;
import com.mshop.util.WebUtil;

public class ReqAction extends MobileAction {

	protected String name;
	protected String pwd;



	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public long getObjectId() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String webProcess(WebContext context) {
		if ("Drivers_list".equals(act)) {
			DESUtil des;
			try {
				des = new DESUtil();
				List<Drivers> driversList = SM.DriversService.list(key, startRow, pagePerSize);
				List<Map<String, String>> list = new ArrayList<Map<String, String>>();
				Map<String, String> map = null;
				for (Drivers drivers : driversList) {
					map = new HashMap<String, String>();
					map.put("id", drivers.getId().toString());
					map.put("name", drivers.getName());
					map.put("dirverNum", des.decrypt(drivers.getDirverNum()));
					map.put("idNum", des.decrypt(drivers.getIdNum()));
					map.put("mobile", drivers.getMobile());
					map.put("address", des.decrypt(drivers.getAddress()));
					list.add(map);
				}
				WebUtil.printStream(context, JSONArray.fromObject(list).toString(),
						true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else if ("Drivers_get".equals(act)) {
			Drivers drivers = SM.DriversService.get(id);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("drivers", drivers);
			WebUtil.printStream(context, JSONArray.fromObject(map).toString(),
					true);
		}else if ("Drivers_count".equals(act)) {
			Long count = SM.DriversService.getCount(key);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("count", count);
			WebUtil.printStream(context, JSONArray.fromObject(map).toString(),
					true);
		}else if ("Users_login".equals(act)) {
			Users u = SM.UsersService.findByNamePwd(name,
					pwd);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("users", u);
			WebUtil.printStream(context, JSONArray.fromObject(map)
					.toString(), true);
		}else {
			Map<String, String> map = new HashMap<String, String>();
			map.put("rst", "commend error");
			WebUtil.printStream(context, JSONArray.fromObject(map).toString(),
					true);
		}
		return null;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the pwd
	 */
	public String getPwd() {
		return pwd;
	}

	/**
	 * @param pwd
	 *            the pwd to set
	 */
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
}
